﻿// =================================================================== 
// 项目说明
//====================================================================
// lsc @Copy Right 2019
// 文件： CarlifeActivityRepository.cs
// 项目名称：斑马车务
// 创建时间：2019-09-06
// 负责人：lsc
// ===================================================================
using System;
using System.Text;
using System.Collections.Generic;
using YouWei.Infrastructure.Entity;
using Dapper.Extensions;
using Dapper;
using YouWei.Infrastructure.Models;

namespace YouWei.Infrastructure.Repository
{
    /// <summary>
    /// 仓储层
    /// </summary>	
    public class CarlifeActivityRepository : BaseRepository<CarlifeActivity>
    {

        #region 构造

        public CarlifeActivityRepository() : base() { }

        public CarlifeActivityRepository(string connectionString) : base(connectionString) { }

        public CarlifeActivityRepository(DatabaseContext dbContext) : base(dbContext) { }

        #endregion

        public Page<CarlifeActivity> Pages(CarlifeActivityModel condtion)
        {
            var dparams = new DynamicParameters();
            string sql = GetSql(condtion, dparams);
            return Pages(condtion.PageIndex, condtion.PageSize, sql, dparams);
        }


        /// <summary>
        /// 拼写查询语句
        /// </summary>
        /// <param name="condtion"></param>
        /// <param name="dparams"></param>
        /// <returns></returns>
        public string GetSql(CarlifeActivityModel condtion, DynamicParameters dparams)
        {
            string sql = "SELECT * FROM [CarlifeActivity] T0 WITH(NOLOCK) WHERE 1=1";
            if (!string.IsNullOrEmpty(condtion.CarShortName))
            {
                sql += " AND T0.CarShortName LIKE @CarShortName";
                dparams.Add("CarShortName", "%" + condtion.CarShortName + "%", System.Data.DbType.String);
            }
            if (!string.IsNullOrEmpty(condtion.WxCode))
            {
                sql += " AND T0.WxCode LIKE @WxCode";
                dparams.Add("WxCode", "%" + condtion.WxCode + "%", System.Data.DbType.String);
            }
            if (!string.IsNullOrEmpty(condtion.CarName))
            {
                sql += " AND T0.CarName LIKE @CarName";
                dparams.Add("CarName", "%" + condtion.CarName + "%", System.Data.DbType.String);
            }
            sql += " ORDER BY T0.ID DESC";
            return sql;
        }

    }
}